﻿/*  
	------------------------------------------------------------------------
	 NQ Software Development Kit Component
	
	 Homepage: http://www.awzhome.de/
	------------------------------------------------------------------------
	
	This Source Code Form is subject to the terms of the Mozilla Public
	License, v. 2.0. If a copy of the MPL was not distributed with this
	file, You can obtain one at http://mozilla.org/MPL/2.0/.
   
	The Original Code is code of NQ Software Development Kit Component.

	The Initial Developer of the Original Code is Andreas Weizel.
	Portions created by the Initial Developer are
	Copyright (C) 2012 Andreas Weizel. All Rights Reserved.
	
	Contributor(s): (none)
	
	------------------------------------------------------------------------
*/

using System.Windows.Controls;
using AWZhome.NQsdk.Helpers;
using System.Windows.Data;
using System.Collections.Generic;
using AWZhome.NQ.Core;
using System;

namespace AWZhome.NQsdk.Visual
{
	/// <summary>
	/// Interaction logic for ComponentServiceInformation.xaml
	/// </summary>
	public partial class ComponentServiceInformation : UserControl
	{
		private ComponentEntry _componentEntry;
		private ServiceEntry _serviceEntry;

		public ComponentServiceInformation()
		{
			InitializeComponent();
		}

		/// <summary>
		/// Sets/gets the component entry to be shown in the control.
		/// </summary>
		public ComponentEntry ComponentEntry
		{
			get
			{
				return _componentEntry;
			}
			set
			{
				_componentEntry = value;
				this.ComponentInfoGrid.DataContext = value;
			}
		}

		/// <summary>
		/// Sets/gets the service entry to be shown in the control.
		/// </summary>
		public ServiceEntry ServiceEntry
		{
			get
			{
				return _serviceEntry;
			}
			set
			{
				_serviceEntry = value;
				this.ServiceInfoGrid.DataContext = _serviceEntry;

				if (_serviceEntry != null)
				{
					// Bind the ServiceInfoGrid and the ListBoxes to the correct objects
					((CollectionViewSource) this.FindResource("InterfaceSortedDataSource")).Source = _serviceEntry.ServiceInfo.InterfaceTypes;
					((CollectionViewSource) this.FindResource("AttachListsSortedDataSource")).Source = _serviceEntry.ServiceInfo.AttachedTo;

					List<ServiceEntry> substitutesList = new List<ServiceEntry>();
					if (_serviceEntry.ServiceInfo.Substitutes != null)
					{
						foreach (Type servInterface in _serviceEntry.ServiceInfo.Substitutes)
						{
							ServiceEntry substitute = new ServiceEntry();
							substitute.ServiceInfo = NQServiceManager.Instance.GetServiceInfo(servInterface);
							substitute.IsSingleInstance = substitute.ServiceInfo.SingleInstance;
							substitute.IsSubstituted = true;
							substitutesList.Add(substitute);
						}
					}
					((CollectionViewSource) this.FindResource("SubstitutedSortedDataSource")).Source = substitutesList;
				}
			}
		}
	}
}
